home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / lsb-base-logging.sh < prev    next >
Encoding:
Text File  |  2007-04-10  |  3.7 KB  |  175 lines

  1. # Default init script logging functions suitable for Ubuntu.
  2. # See /lib/lsb/init-functions for usage help.
  3.  
  4. log_use_usplash () {
  5.     if [ "${loop:-n}" = y ]; then
  6.         return 1
  7.     fi
  8.     type usplash_write >/dev/null 2>&1
  9. }
  10.  
  11. log_to_console () {
  12.     [ "${loop:-n}" != y ] || return 0
  13.     [ "${QUIET:-no}" != yes ] || return 0
  14.  
  15.     # Only output to the console when we're given /dev/null
  16.     stdin=`readlink /proc/self/fd/0`
  17.     [ "${stdin#/dev/null}" != "$stdin" ] || return 0
  18.  
  19.     func=$1
  20.     shift
  21.  
  22.     loop=y $func "$@" </dev/console >/dev/console 2>&1 || true
  23. }
  24.  
  25. log_success_msg () {
  26.     if log_use_usplash; then
  27.         usplash_write "STATUS $*" || true
  28.     fi
  29.  
  30.     log_to_console log_success_msg "$@"
  31.  
  32.     echo " * $@"
  33. }
  34.  
  35. log_failure_msg () {
  36.     if log_use_usplash; then
  37.         usplash_write "STATUS $*" || true
  38.     fi
  39.  
  40.     log_to_console log_failure_msg "$@"
  41.  
  42.     if log_use_fancy_output; then
  43.         RED=`$TPUT setaf 1`
  44.         NORMAL=`$TPUT op`
  45.         echo " $RED*$NORMAL $@"
  46.     else
  47.         echo " * $@"
  48.     fi
  49. }
  50.  
  51. log_warning_msg () {
  52.     if log_use_usplash; then
  53.         usplash_write "STATUS $*" || true
  54.     fi
  55.  
  56.     log_to_console log_warning_msg "$@"
  57.  
  58.     if log_use_fancy_output; then
  59.         YELLOW=`$TPUT setaf 3`
  60.         NORMAL=`$TPUT op`
  61.         echo " $YELLOW*$NORMAL $@"
  62.     else
  63.         echo " * $@"
  64.     fi
  65. }
  66.  
  67. log_begin_msg () {
  68.     log_daemon_msg "$1"
  69. }
  70.  
  71. log_daemon_msg () {
  72.     if [ -z "$1" ]; then
  73.         return 1
  74.     fi
  75.  
  76.     if log_use_usplash; then
  77.         usplash_write "TEXT $*" || true
  78.     fi
  79.  
  80.     log_to_console log_daemon_msg "$@"
  81.  
  82.     if log_use_fancy_output && $TPUT xenl >/dev/null 2>&1; then
  83.         COLS=`$TPUT cols`
  84.         if [ "$COLS" ]; then
  85.             COL=`$EXPR $COLS - 7`
  86.         else
  87.             COL=73
  88.         fi
  89.         # We leave the cursor `hanging' about-to-wrap (see terminfo(5)
  90.         # xenl, which is approximately right). That way if the script
  91.         # prints anything then we will be on the next line and not
  92.         # overwrite part of the message.
  93.  
  94.         # Previous versions of this code attempted to colour-code the
  95.         # asterisk but this can't be done reliably because in practice
  96.         # init scripts sometimes print messages even when they succeed
  97.         # and we won't be able to reliably know where the colourful
  98.         # asterisk ought to go.
  99.  
  100.         printf " * $*       "
  101.         # Enough trailing spaces for ` [fail]' to fit in; if the message
  102.         # is too long it wraps here rather than later, which is what we
  103.         # want.
  104.         $TPUT hpa `$EXPR $COLS - 1`
  105.         printf ' '
  106.     else
  107.         echo " * $@"
  108.         COL=
  109.     fi
  110. }
  111.  
  112. log_progress_msg () {
  113.     :
  114. }
  115.  
  116. log_end_msg () {
  117.     if [ -z "$1" ]; then
  118.         return 1
  119.     fi
  120.  
  121.     if log_use_usplash; then
  122.         if [ "$1" -eq 0 ]; then
  123.             usplash_write "SUCCESS OK" || true
  124.         else
  125.             usplash_write "FAILURE failed" || true
  126.         fi
  127.     fi
  128.  
  129.     log_to_console log_end_msg "$@"
  130.  
  131.     if [ "$COL" ] && [ -x "$TPUT" ]; then
  132.         printf "\r"
  133.         $TPUT hpa $COL
  134.         if [ "$1" -eq 0 ]; then
  135.             echo "[ OK ]"
  136.         else
  137.             printf '['
  138.             $TPUT setaf 1 # red
  139.             printf fail
  140.             $TPUT op # normal
  141.             echo ']'
  142.         fi
  143.     else
  144.         if [ "$1" -eq 0 ]; then
  145.             echo "   ...done."
  146.         else
  147.             echo "   ...fail!"
  148.         fi
  149.     fi
  150.     return $1
  151. }
  152.  
  153. log_action_msg () {
  154.     if log_use_usplash; then
  155.         usplash_write "TEXT $*" || true
  156.     fi
  157.  
  158.     log_to_console log_action_msg "$@"
  159.  
  160.     echo " * $@"
  161. }
  162.  
  163. log_action_begin_msg () {
  164.     log_daemon_msg "$@..."
  165. }
  166.  
  167. log_action_cont_msg () {
  168.     log_daemon_msg "$@..."
  169. }
  170.  
  171. log_action_end_msg () {
  172.     # In the future this may do something with $2 as well.
  173.     log_end_msg "$1" || true
  174. }
  175.